<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="../../../common/common-jstl.jspf" %>
<%@ include file="../../../common/common-easyui.jspf" %>
<%@ include file="../../../common/common-layer.jspf" %>
<!DOCTYPE html >
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
        .container {
            width: 100%;
            height: 100px;
            background-color: #F5F5F5;
        }

        .content {
            width: 100%;
            height: 80%;

        }

        .content table {
            border-collapse: collapse;
            width: 100%;
        }

        .content table td, .content table th {
            border: 1px solid #ccc;
            padding: 7px;
            text-align: center;
        }

        .title {
            width: 100%;
            height: 32%;
            background-color: #5E5E5E;
        }

        .title > span {
            color: white;
            font-size: 12px;
            font-family: "黑体";
            line-height: 32px;
            text-indent: 1em;
            display: block;
        }

    </style>
</head>
<body>
<div class="container">
    <div class="content">
        <div class="title"><span>导入主观题</span></div>
        <form id="fd" action="importController?flag=question" method="post" enctype="multipart/form-data">
            <table>
                <tr>
                    <th>选择导入EXCEL文件:</th>
                    <td><input type="file" name="excelFile"/></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="button" onclick="submitData();" value="  导 入  "/></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div>
    <table id="dg" title="主观题维护表" class="easyui-datagrid" style="width:100%;height:100%"
           data-options="pagination:true,
				url:'subjectiveInfoController?flag=list',
				toolbar:'#toolbar',
				rownumbers:'true', fitColumns:'true', singleSelect:'true',
			    pageList:[5,10,15,20],
			    pageSize:10,
			    displayMsg:'当前显示从 {from} 到 {to} 共 {total} 记录'"
    >
        <thead>
        <tr>
            <th data-options="field:'subId'" width="50">主观题编号</th>
            <th data-options="field:'question'" width="50">题干</th>
            <th data-options="field:'answer'" width="50">参考答案</th>

            <th data-options="field:'courseId'" width="50">科目编号</th>
        </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:'true'" onclick="newSubjective()">添加题型</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit', plain:'true'"
           onclick="editSubjective()">编辑题型</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove', plain:'true'"
           onclick="destroySubjective()">移除题型</a>
    </div>
    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
         data-options="closed:'true', buttons:'#dlg-buttons'">
        <div class="ftitle">主观题信息</div>
        <form id="fm" method="post">
            <div class="fitem">
                <label>题干:</label>
                <input name="question">
            </div>

            <div class="fitem">
                <label>参考答案:</label>
                <input name="answer">
            </div>

            <div class="fitem">
                <label>科目编号:</label>
                <input name="courseId">
            </div>

        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveSubjective()">Save</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
           onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
    </div>
</div>
<script type="text/javascript">
    function submitData() {
        var form = new FormData(document.getElementById("fd"));
        $.ajax({
            url: "importController?flag=question",
            type: "post",
            data: form,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data == "ok") {
                    layer.msg("导入成功");

                } else if (data == "false") {
                    layer.msg("请上传excel文件");
                }
            },
            error: function (e) {
                layer.msg("导入出现错误！！");

            }
        });
        get();//此处为上传文件的进度条
    }
    //添加函数
    function newSubjective() {
        $('#dlg').dialog('open').dialog('setTitle', '添加主观题');
        $('#fm').form('clear');
        url = 'subjectiveInfoController?flag=add';
    }
    //修改函数
    function editSubjective() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '修改主观题');
            $('#fm').form('load', row);
            url = 'subjectiveInfoController?flag=update&subId=' + row.subId;
        }
    }
    //保存函数
    function saveSubjective() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {

                if (data == "ok") {
                    $('#dlg').dialog('close');		// 清除数据
                    $('#dg').datagrid('reload');	// 重新加载数据
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                }
            }
        });
    }
    //删除函数
    function destroySubjective() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '确定删除吗?', function (r) {
                if (r) {
                    $.get('subjectiveInfoController', {flag: "dele", subId: row.subId}, function (data) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload');	// 重新加载数据
                        } else {
                            $.messager.show({	//错误提示
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    });
                }
            });
        }
    }
</script>
</body>
</html>